package com.bjpowernode.test07;

import java.util.Arrays;
import java.util.Random;

public class TestZimu {
    public static void main(String[] args) {
        char[] chars = new char[100];
        chars = addChar(chars);
        countChar(chars);


    }
    //定义方法，填充字符数组
    public static char[] addChar(char[] chars){
        Random random = new Random();
        for (int i=0;i<chars.length;i++){
            int num = random.nextInt(26);
            char c = (char)('a'+num);
            chars[i]=c;
        }
        return chars;
    }

    //定义方法，统计数组中每个字母出现的次数
    public static void countChar(char[] chars){
       int count = 0;
       for (int i=0;i<26;i++){
           char m = (char)('a'+i);
           for (char c:chars){
               if (m == c){
                   count++;
               }
           }
           System.out.println("字符"+m+"出现了"+count+"次");
           count = 0;
       }
    }

}
